Compact request event history in role prompts - #5
Merged
rica-v3 merged 2 commits intoJul 27, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a configurable prompt-time projection of persisted request event history to keep model prompts bounded while preserving full audit history on disk. It adds a shared selection/backfill algorithm (recent tail + newest missing role evidence), propagates configuration through runtimes, and documents how to validate and measure the impact via telemetry.
Changes:
- Add global
prompt_contextruntime configuration (default enabled,recent_events=8,max_events=16) and validation during config load/scaffold. - Introduce
shared/prompt_context.pyto project request event histories for prompts and render a content-free compaction notice. - Apply the projection + notice to normal role prompts, contract repair prompts, and the research decision prompt; propagate config through
TeamServiceto model-facing runtimes; add dedicated unit tests and documentation.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| workflows/roles/research.py | Projects request history for the research decision prompt and emits a compaction notice + runtime log line when applicable. |
| workflows/orchestration/team_service.py | Propagates prompt_context config into all model-facing runtimes created by TeamService. |
| runtime/base_runtime.py | Centralizes request projection + compaction logging and injects the notice + projected request record into normal and repair prompts. |
| runtime/research_runtime.py | Passes the runtime prompt_context_config through to the research decision prompt builder. |
| shared/prompt_context.py | Implements the projection/backfill algorithm and renders the content-free compaction notice. |
| shared/models.py | Adds PromptContextRuntimeConfig and wires it into TeamRuntimeConfig. |
| shared/config.py | Loads/validates prompt_context from team_runtime.yaml (type checks, positivity, and max_events >= recent_events). |
| templates/scaffold/team_runtime.yaml | Adds default prompt_context section to new scaffolds. |
| tests/test_prompt_context.py | Adds focused unit tests for projection/backfill behavior, prompt integration, config defaults/validation, and TeamService propagation. |
| models.py | Re-exports PromptContextRuntimeConfig via the compatibility module. |
| docs/configuration_guide.md | Documents prompt_context configuration, algorithm, and a worked example. |
| docs/specification.md | Updates config specification and adds prompt projection policy description. |
| docs/operations_guide.md | Updates operational description of prompt request records to reflect bounded projection and canonical history path. |
| docs/telemetry.md | Adds guidance for measuring prompt compaction impact using telemetry and runtime logs. |
| docs/implementation.md | Documents ownership/location of the new prompt-context projection module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prompt_contextconfiguration with defaultsenabled: true,recent_events: 8, andmax_events: 16.Behavior and boundaries
.teams_runtime/requests/<request_id>.jsonrecords are unchanged and retain every event.prompt_context.enabled: false, which restores full event-history prompt inclusion.Selection policy
recent_eventsentries by list position.max_eventsis reached.Role evidence is a
role_reportintypeor legacyevent_type, or an event with non-emptypayload.roleandpayload.status. Identity usespayload.role, thenactor.Validation
python -m unittest discover -s teams_runtime/tests(769 tests passed)python -m unittest teams_runtime.tests.test_prompt_context(9 tests passed)python -m compileall -q teams_runtimegit diff --checkTracks #2.